package org.dbrd.model;

public abstract class AbstractBugReport {

	public static final int NON_DUPLICATE = Integer.MAX_VALUE;

	public static boolean isDuplicate(int id, int duplicateId) {
		return duplicateId != NON_DUPLICATE && duplicateId != id;
	}

	protected final int id;

	protected String originalSummary;

	protected String processedSummary;

	protected String originalDescription;

	protected String processedDescription;

	protected int duplicateId;

	// ---
	private final String component;

	public String getComponent() {
		return component;
	}

	public int getPriority() {
		return priority;
	}

	public String getVersion() {
		return version;
	}

	public String getSubComponent() {
		return subComponent;
	}

	public String getIssueType() {
		return issueType;
	}

	private final int priority;

	private final String version;

	private final String subComponent;

	private final String issueType;

	public String getProcessedSummary() {
		return this.processedSummary;
	}

	// public AbstractBugReport(int id, String originalSummary, int duplicateId)
	// {
	// this(id, originalSummary, "", null, "", duplicateId);
	// }

	public AbstractBugReport(final int id, final String originalSummary, final String processedSummary, final String originalDescription,
			final String processedDescription, final int duplicateId, final int priority, final String version, final String subComponent,
			final String issueType, String component) {
		this.id = id;
		this.originalSummary = originalSummary;
		this.processedSummary = processedSummary;
		this.originalDescription = originalDescription;
		this.processedDescription = processedDescription;
		this.duplicateId = duplicateId;

		this.priority = priority;
		this.version = version;
		this.subComponent = subComponent;
		this.component = component;
		this.issueType = issueType;
	}

	protected void clearSummaryAndDescription() {
		this.originalDescription = null;
		this.originalSummary = null;
		this.processedDescription = null;
		this.processedSummary = null;
	}

	// public AbstractBugReport(int id, String originalSummary, String
	// processedSummary, int duplicateId) {
	// this(id, originalSummary, processedSummary, null, "", duplicateId);
	// }

	// public AbstractBugReport(int id, String originalSummary, String
	// processedSummary, int duplicateId) {
	// this(id, originalSummary, null, )
	// }

	public boolean isDuplicated() {
		return this.duplicateId != NON_DUPLICATE && this.duplicateId != this.id;
	}
	
	
	public void makeItNotDuplicate()
	{
		this.duplicateId = NON_DUPLICATE; 
	}
	

	public int getId() {
		return this.id;
	}

	// public String getSummary() {
	// return this.originalSummary;
	// }

	public String getOriginalSummary() {
		if (this.originalSummary == null) {
			throw new RuntimeException("this is impossible.");
		}
		return this.originalSummary;
	}

	public String getProcessedDescription() {
		return this.processedDescription;
	}

	public String getOriginalDescription() {
		if (this.originalDescription == null) {
			throw new RuntimeException("this is impossible.");
		}
		return this.originalDescription;
	}

	public int getDuplicateId() {
		return this.duplicateId;
	}

	@Override
	public String toString() {
		final StringBuilder builder = new StringBuilder();
		builder.append(" ID = ").append(this.id);
		return builder.toString();
	}
}
